'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async login() {
    const { ctx } = this;
    const user = await ctx.service.user.login(ctx.request.body.account_id);
    if( user&&user.password == ctx.request.body.password){
      ctx.body = '登录成功';
    }else{
      ctx.body = '登录失败';
    }
  }
  async register() {
    const { ctx } = this;
    for (const key in ctx.request.body) {
			if(!ctx.request.body[key]){
        ctx.body = `${key}参数不能为空`;
				return
			}
		}
    const user = await ctx.service.user.rgister(ctx.request.body);
    ctx.body = user;
  }
}

module.exports = HomeController;
